<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>新增种子·思通投研·让数据驱动投资价值!</title>
	
	<link href="${pageContext.request.contextPath }/img/webLogoIcon.png" rel="shortcut icon">
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/font-awesome.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/custom.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/style.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/datatables.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/toastr.min.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath }/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/jquery.searchableSelect.css" rel="stylesheet" type="text/css">
    <style>
		.select2_demo_1 {
			float: left;
			width: 120px;
			display: inline;
			margin-left: 10px;
		}
		
		.form-control {
			display: inline;
		}
		
		.col-sm-3 {
			float: right;
			width: 560px;
		}
		
		.input-group {
			float: right;
			width: 240px;
			margin-left: 5px;
		}
		
		.checkbox {
		    padding-left: 35px;
		    float: left;
		}
	</style>
</head>

<body>

    <div id="wrapper">

        <nav class="navbar-default navbar-static-side" role="navigation">
        	<%request.setAttribute("LEFT", "websitelist");%>
			<%@include file="left-factory.jsp"%>
        </nav>

        <div id="page-wrapper" class="gray-bg">
        <div class="row border-bottom">
        <jsp:include page="head-factory.jsp" flush="true" />
        </div>
            <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-10">
                    <h2>新增策略</h2>
                </div>
            </div>
			<div class="wrapper wrapper-content">
				<div class="ibox-content">
					<form action="${pageContext.request.contextPath}/spiderconfig/test"
						method="post" target="_blank">
						<span style="font-size: 17px;" id="websiteId"
							data-id="${websiteId }">网站名称:${websitename } </span>
						<button class="btn btn-white pull-right"
							onclick="javascrtpt:window.location.href='${pageContext.request.contextPath }/listseed?websiteId=${websiteId}'"
							type="button">返回</button>
						<div class="table-responsive" style="margin-top: 5%;">
							<div class="search-result">
								<span style="font-size: 17px;">添加一个在【${websitename }】下种子地址配置信息</span>
								<div style="display: inline; float: right;">
									线程数:<select class="form-control"
										style="display: inline; width: auto;" id="seedthreadconfig"
										name="seedthreadconfig">
										<option value="1" selected ${ SpiderSeedConfigUtilOb.seed_thread_config ==1 ? 'selected':'' }>1条</option>
										<option value="5" ${ SpiderSeedConfigUtilOb.seed_thread_config ==5 ? 'selected':'' }>5条</option>
										<option value="10" ${ SpiderSeedConfigUtilOb.seed_thread_config ==10 ? 'selected':'' }>10条</option>
									</select> &nbsp;&nbsp;&nbsp;&nbsp;抓取间隔:<select class="form-control"
										style="display: inline; width: auto;" id="seedintervalconfig"
										name="seedintervalconfig">
										<option value="600000" ${ SpiderSeedConfigUtilOb.seed_interval_config ==600000 ? 'selected':'' }>10分钟</option>
										<option value="1800000" ${ SpiderSeedConfigUtilOb.seed_interval_config ==1800000 ? 'selected':'' }selected>30分钟</option>
										<option value="3600000" ${ SpiderSeedConfigUtilOb.seed_interval_config ==3600000 ? 'selected':'' }>60分钟</option>
									</select> &nbsp;&nbsp;&nbsp;&nbsp;访问URL间隔:<select class="form-control"
										style="display: inline; width: auto;" id="seedsleepconfig"
										name="seedsleepconfig">
										<option value="1000" ${ SpiderSeedConfigUtilOb.seed_sleep_config ==1000 ? 'selected':'' }>1秒</option>
										<option value="2000" ${ SpiderSeedConfigUtilOb.seed_sleep_config ==2000 ? 'selected':'' }>2秒</option>
										<option value="3000" ${ SpiderSeedConfigUtilOb.seed_sleep_config ==3000 ? 'selected':'' }>3秒</option>
										<option value="4000" ${ SpiderSeedConfigUtilOb.seed_sleep_config ==4000 ? 'selected':'' }>4秒</option>
										<option value="5000" ${ SpiderSeedConfigUtilOb.seed_sleep_config ==5000 ? 'selected':'' } selected>5秒</option>
									</select>
								</div>
							</div>
							<div class="hr-line-dashed"></div>

							<div class="panel-body">

								<fieldset class="form-horizontal" style="margin-top: 3%;">

									<div class="form-group">
										<label class="col-sm-2 control-label"><span
											style="color: red; font-size: 16px; line-height: 0px;">*</span>抓取配置名称:</label>
										<div class="col-sm-10">
											<input type="text" id="seedname" name="seedname"
												class="form-control" style="width: 88%;" value="${SpiderSeedConfigUtilOb.seed_util_name }"
												placeholder="抓取配置名称">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label"><span
											style="color: red; font-size: 16px; line-height: 0px;">*</span>配置标题规则:</label>
										<div class="col-sm-10">
											<input type="text" id="seedtitleconfig" name="seedtitleconfig"
												class="form-control" style="width: 88%;" value="${SpiderSeedConfigUtilOb.seed_title_config }"
												placeholder="请输入配置标题规则">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">配置来源规则:</label>
										<div class="col-sm-10">
											<input type="text" id="seedoriginconfig" name="seedoriginconfig"
												class="form-control" style="width: 88%;" value="${SpiderSeedConfigUtilOb.seed_origin_config }"
												placeholder="请输入配置来源规则">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">配置来源URL规则:</label>
										<div class="col-sm-10">
											<input type="text" id="seedoriginurlconfig" name="seedoriginurlconfig"
												class="form-control" style="width: 88%;" value="${SpiderSeedConfigUtilOb.seed_origin_url_config }"
												placeholder="请输入配置来源URL规则">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label"><span
											style="color: red; font-size: 16px; line-height: 0px;">*</span>配置日期规则:</label>
										<div class="col-sm-10">
											<input type="text" id="seeddateconfig"
												name="seeddateconfig" class="form-control" value="${SpiderSeedConfigUtilOb.seed_date_config }"
												style="width: 88%;" placeholder="请输入配置日期规则项">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label"><span
											style="color: red; font-size: 16px; line-height: 0px;">*</span>配置正文解析规则:</label>
										<div class="col-sm-10">
											<input type="text" id="seedtextconfig"
												name="seedtextconfig" class="form-control" value="${SpiderSeedConfigUtilOb.seed_text_config }"
												style="width: 88%;" placeholder="请输入配置正文解析规则">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label"><span
											style="color: red; font-size: 16px; line-height: 0px;">*</span>配置详情Url正则:</label>
										<div class="col-sm-10">
											<input type="text" id="url_reg"
												name="url_reg" class="form-control" value="${SpiderSeedConfigUtilOb.url_reg }"
												style="width: 88%;" placeholder="请输入配置正文解析规则">
										</div>
									</div>
								</fieldset>
<!-- 								<button class="btn btn-primary" -->
<!-- 									style="margin-left: 20%; margin-top: 2%;" onclick="check()" -->
<!-- 									type="submit">测试种子</button> -->
								<c:if test="${ SpiderSeedConfigUtilOb.id == null }">
									<button class="btn btn-primary"
										style="margin-left: 38%; margin-top: 2%;" id="addbutton"
										onclick="addConfig()" type="button">添加</button>
								</c:if>
								<c:if test="${ SpiderSeedConfigUtilOb.id != null }">
									<button class="btn btn-primary"
										style="margin-left: 38%; margin-top: 2%;" id="addbutton"
										onclick="save(${ SpiderSeedConfigUtilOb.id })" type="button">保存</button>
								</c:if>
							</div>
						</div>
					</form>
				</div>
			</div>
			<jsp:include page="footer.jsp" flush="true" />
        </div>
        </div>



    <!-- Mainly scripts -->
    <script src="${pageContext.request.contextPath }/js/jquery-2.1.1.js"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/jquery.metisMenu.js"></script>
    <script src="${pageContext.request.contextPath }/js/jquery.slimscroll.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/jquery.jeditable.js"></script>
    <script src="${pageContext.request.contextPath }/js/datatables.min.js"></script>
    
    <!-- Peity -->
    <script src="${pageContext.request.contextPath }/js/jquery.peity.min.js"></script>

    <!-- Custom and plugin javascript -->
    <script src="${pageContext.request.contextPath }/js/inspinia.js"></script>
    <script src="${pageContext.request.contextPath }/js/pace.min.js"></script>

    <!-- Peity -->
    <script src="${pageContext.request.contextPath }/js/peity-demo.js"></script>

	<!-- toastr -->
	<script src="${pageContext.request.contextPath }/js/plugins/toastr/toastr.min.js"></script>
	<!-- Sweet alert -->
	<script src="${pageContext.request.contextPath }/js/plugins/sweetalert/sweetalert.min.js"></script>
	
	
    <script src="${pageContext.request.contextPath }/js/jquery.searchableSelect.js"></script>
    <!-- Page-Level Scripts -->
    <script>
    function addConfig(){
    	if($("#seedtitleconfig").val()==null||$("#seedtitleconfig").val()=="")
    	{
    		toastr.error('请填写需要配置的标题规则')
    		return;
    	}else if($("#seeddateconfig").val()==null||$("#seeddateconfig").val()=="")
    	{
    		toastr.error('请填写需要配置的日期规则')
    		return;
    	}else if($("#seedtextconfig").val()==null||$("#seedtextconfig").val()=="")
    	{
    		toastr.error('请填写需要配置的正文规则')
    		return;
    	}else if($("#url_reg").val()==null||$("#url_reg").val()=="")
    	{
    		toastr.error('请填写需要配置的详情url正则')
    		return;
    	}
     	   data = {
     			seedname : $("#seedname").val(),
      			seedtype : $("#seedtype").val(),
      			websiteId : $("#websiteId").attr("data-id"),
      			seeddateconfig : $("#seeddateconfig").val(),
      			seedintervalconfig : $("#seedintervalconfig").val(),
      			seedsleepconfig : $("#seedsleepconfig").val(),
      			seedtextconfig : $("#seedtextconfig").val(),
      			seedtextconfigtype : $("#seedtype").val(),
      			seedthreadconfig : $("#seedthreadconfig").val(),
      			seedtitleconfig : $("#seedtitleconfig").val(),
      			seedurlconfig : $("#seedurlconfig").val(),
      			seeddateconfig : $("#seeddateconfig").val(),
      			seedlinkurlconfig : $("#seedlinkurlconfig").val(),
      			seedspidertype : 2,
      			url_reg:$("#url_reg").val(),
      			otherwebsiteId:$("#websiteId").attr("data-id")
     		}
    	$.ajax({
    		url : "${pageContext.request.contextPath}/websitetactics/insertseed",
    		type : "post",
    		data : data,
    		success : function(res) {
    			console.log(res)
    			if (res.status == 200) {
    				toastr.success(res.msg);
    				setTimeout(() => {
    					window.location.href = "${pageContext.request.contextPath}/listseed?websiteId="+${websiteId};
					}, 3000);
    			} else {
    				toastr.error(res.msg);
    			}
    		},
    		error : function(e) {
    			toastr.error(res.msg);
    			window.clearInterval(timer);
    		}
    	});
    }
    
    function save(id){
    	if($("#seedtitleconfig").val()==null||$("#seedtitleconfig").val()=="")
    	{
    		toastr.error('请填写需要配置的标题规则')
    		return;
    	}else if($("#seeddateconfig").val()==null||$("#seeddateconfig").val()=="")
    	{
    		toastr.error('请填写需要配置的日期规则')
    		return;
    	}else if($("#seedtextconfig").val()==null||$("#seedtextconfig").val()=="")
    	{
    		toastr.error('请填写需要配置的正文规则')
    		return;
    	}else if($("#url_reg").val()==null||$("#url_reg").val()=="")
    	{
    		toastr.error('请填写需要配置的详情url正则')
    		return;
    	}
     	   data = {
     			id:id,
     			seedname : $("#seedname").val(),
      			seedtype : $("#seedtype").val(),
      			websiteId : $("#websiteId").attr("data-id"),
      			seeddateconfig : $("#seeddateconfig").val(),
      			seedintervalconfig : $("#seedintervalconfig").val(),
      			seedsleepconfig : $("#seedsleepconfig").val(),
      			seedtextconfig : $("#seedtextconfig").val(),
      			seedtextconfigtype : $("#seedtype").val(),
      			seedthreadconfig : $("#seedthreadconfig").val(),
      			seedtitleconfig : $("#seedtitleconfig").val(),
      			seedurlconfig : $("#seedurlconfig").val(),
      			seeddateconfig : $("#seeddateconfig").val(),
      			seedlinkurlconfig : $("#seedlinkurlconfig").val(),
      			seedspidertype : 2,
      			url_reg:$("#url_reg").val(),
      			otherwebsiteId:$("#websiteId").attr("data-id")
     		}
//         }
    	$.ajax({
    		url : "${pageContext.request.contextPath}/websitetactics/save",
    		type : "post",
    		data : data,
    		success : function(res) {
    			console.log(res)
    			if (res.status == 200) {
    				toastr.success(res.msg);
    				setTimeout(() => {
    					window.location.href = "${pageContext.request.contextPath}/listseed?websiteId="+${websiteId};
					}, 3000);
    			} else {
    				toastr.error(res.msg);
    			}
    		},
    		error : function(e) {
    			toastr.error(res.msg);
    			window.clearInterval(timer);
    		}
    	});
    }
  function check(){
    	
    	if($("#seedname").val()==null||$("#seedname").val()=="")
    	{
    		toastr.error('请填写需要采集的地址名')
    		return;
    	}else if($("#seedurllist").val()==null||$("#seedurllist").val()=="")
    	{
    		toastr.error('请填写需要采集的地址列表')
    		return;
    	}else if($("#seedtype").val()==null||$("#seedtype").val()==0)
    	{
    		toastr.error('请填写需要配置的正文类型')
    		return;
    	}else if($("#seedurlconfig").val()==null||$("#seedurlconfig").val()=="")
    	{
    		toastr.error('请填写需要配置的列表规则')
    		return;
    	}else if($("#seedtitleconfig").val()==null||$("#seedtitleconfig").val()=="")
    	{
    		toastr.error('请填写需要配置的标题规则')
    		return;
    	}else if($("#seeddateconfig").val()==null||$("#seeddateconfig").val()=="")
    	{
    		toastr.error('请填写需要配置的日期规则')
    		return;
    	}else if(!$("#checkbox1").prop('checked')&&!$("#checkbox2").prop('checked')&&!$("#checkbox3").prop('checked'))
    	{
    		toastr.error('请选择需要配置的存储规则')
    		return;
    	}else if($("#seedtextconfig").val()==null||$("#seedtextconfig").val()=="")
    	{
    		toastr.error('请填写需要配置的正文规则')
    		return;
    	}else if($("#se2").val()==null||$("#se2").val()=="")
    	{
    		toastr.error('请选择文章的分类')
    		return;
    	}
    	var sRegex = '^((https|http|ftp|rtsp|mms)?://)' + '?(([0-9a-z_!~*\'().&=+$%-]+: )?[0-9a-z_!~*\'().&=+$%-]+@)?'
        + '(([0-9]{1,3}.){3}[0-9]{1,3}'
        + '|' 
        + '([0-9a-z_!~*\'()-]+.)*'
        + '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].'
        + '[a-z]{2,6})'
        + '(:[0-9]{1,4})?'
        + '((/?)|'
        + '(/[0-9a-z_!~*\'().;?:@&=+$,%#-]+)+/?)$';
    	var re = new RegExp(sRegex);
    	if (!re.test($("#seedurllist").val())) {
        	toastr.error('url填写不正确')
        	return;
        }
    	
    	
    }
  
  
  
//跑马灯方法 
// 	 function init(){
// 		    //获取标题
// 		    var title=document.title;
// 		    //分割字符串--->字符数组
// 		    var arr=title.split("");
// 		    //删除第一个元素并返回该元素
// 		    var e=arr.shift();
// 		    //把一个对象添加到数组末尾
// 		    arr.push(e);
// 		    //把数组转换成字符串
// 		    var marquee=arr.join("");
// 		    //返回给浏览器
// 		    document.title=marquee;
// 		    //定时一直执行
// 		    window.setTimeout("init()",1000);
// 		}
// 		window.onload=init;
	 
    </script>

</body>

</html>
